package com.unhz.taigu.interface_controllers.areaDict;

import com.unhz.generator.pojo.AreaDict;
import com.unhz.generator.utils.EmptyUtil;
import com.unhz.generator.utils.JsonResult;
import com.unhz.taigu.service.AreaDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 沈佳庆
 * @Description: 地区行政编码
 * @Date: Created in 下午 5:17 2018/3/6 0006
 * @Modified By: V1.0.0
 */
@RestController
@RequestMapping("/IAreaDict")
public class IAreaDictController {

    @Autowired
    private AreaDictService areaDictService;


    /**
     * 查询某个城市下面的地区
     * @param areaCode
     * @return
     */
    @RequestMapping("/findCountry")
    public JsonResult findCountry(@RequestParam("areaCode")String areaCode){
        List<AreaDict> list = areaDictService.findCountry(areaCode);
        if(EmptyUtil.isEmpty(list)){
            return JsonResult.failure("查询地区失败!");
        }
        return JsonResult.success("查询地区成功!",list);
    }

    /**
     * 查询某个省份下面的城市
     */
    @RequestMapping("/findCity")
    public JsonResult findCity(@RequestParam("areaCode")String areaCode){
        List<AreaDict> list = areaDictService.findCity(areaCode);
        if(EmptyUtil.isEmpty(list)){
            return JsonResult.failure("查询城市失败!");
        }
        return JsonResult.success("查询城市成功!",list);
    }

    /**
     * 查询所有省份
     * @return
     */
    @RequestMapping("/findProvince")
    public JsonResult findProvince(){
        List<AreaDict> list = areaDictService.findArea();
        if(EmptyUtil.isEmpty(list)){
            return JsonResult.failure("查询省份失败!");
        }
        return JsonResult.success("查询省份成功!",list);
    }
}
